package com.aptemo.webetek.server.data;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.gwt.user.client.rpc.IsSerializable;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class LoginInfo implements IsSerializable
{

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key			key;

	@Persistent
	private String		email;

	@Persistent
	private Set<Key>	users		= new HashSet<Key>();

	@Persistent
	private List<Key>	favourites	= new ArrayList<Key>();

	private String		sid;

	public LoginInfo(String email)
	{
		this.setEmail(email);
	}

	public void setEmail(String email)
	{
		this.email = email;
	}

	public String getEmail()
	{
		return email;
	}

	public void setKey(Key key)
	{
		this.key = key;
	}

	public Key getKey()
	{
		return key;
	}

	public String getSid()
	{
		if (sid == null)
		{
			this.sid = KeyFactory.keyToString(key);
		}
		return sid;
	}

	public List<Key> getFavourites()
	{
		return favourites;
	}

	public void addFavourite(Key key)
	{
		favourites.add(key);
	}

	public void removeFavourite(Key key)
	{
		favourites.remove(key);
	}

	public Set<Key> getUsers()
	{
		return users;
	}

	public void setUsers(Set<Key> users)
	{
		this.users = users;
	}

}
